home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-08-14 | 6.9 KB | 178 lines | [TEXT/MPS ] |
- PROGRAM Tips1;
-
- USES Memtypes,QuickDraw,OSIntf,ToolIntf,PackIntf,MacPrint;
-
- CONST
- PostScriptBegin = 190;
- PostScriptEnd = 191;
- PostScriptHandle = 192;
- PostScriptBeginNoSave = 196;
-
- PROCEDURE SendPostScript(theComment: Str255);
- VAR
- PSCommand : Str255;
- CommandHdl : Handle;
- CRString : Str255;
- theError : OSErr;
- BEGIN
- CRString := ' ';
- CRString[1] := CHR(13);
- PSCommand := theComment;
- PSCommand := CONCAT(PSCommand, CRString);
- theError := PtrToHand(POINTER(ORD(@PSCommand) + 1), CommandHdl,
- LENGTH(PSCommand));
- if theError <> noErr THEN BEGIN
- (* Handle the error! *)
- END;
- PicComment(PostScriptHandle, LENGTH(PSCommand), CommandHdl);
- DisposHandle(CommandHdl);
- END;
-
- PROCEDURE SetFont(fontName: Str255; fontSize: INTEGER; fontStyle: Style);
- VAR
- theFontID: INTEGER;
- thePenLoc: Point;
- BEGIN
- GetFNum(fontName, theFontID); (* Get the font ID. *)
- TextFont(theFontID); (* Set it. *)
- TextSize(fontSize); (* Set the size... *)
- TextFace(fontStyle); (* ...and the style. *)
- GetPen(thePenLoc); (* Save the current pen position. *)
- DrawChar(' '); (* Draw a space so the font gets downloaded.*)
- MoveTo(thePenLoc.h, thePenLoc.v); (* Restore the original pen position. *)
- END;
-
- PROCEDURE DrawStuff(theWorld : Rect);
- { Draw whatever you want here. Make sure it fits in the world rectangle. }
- BEGIN
- (* First, let's define a PostScript dictionary. Since we aren't actually *)
- (* drawing anything, we don't need to turn off Quickdraw (ie. we don't need *)
- (* the PostScriptBegin/End comments). *)
- (* First create a dictionary that can hold 10 objects. *)
- SendPostScript('/mydict 10 dict def');
- (* Now make it current. All implicit operations from now on will go to *)
- (* mydict. *)
- SendPostScript('mydict begin');
- (* Now define the routine to save the definition of bu on the stack, and*)
- (* then define it to do nothing. *)
- SendPostScript('/killbu {//md /bu get //md /bu {} put} def');
- (* Now define a routine to pop the old definition of bu off the stack, *)
- (* and back into the bu symbol. *)
- SendPostScript('/restorebu {//md exch /bu exch put} def');
- (* Now do the same for bn. *)
- SendPostScript('/killbn {//md /bn get //md /bn {} put} def');
- SendPostScript('/restorebn {//md exch /bn exch put} def');
- (* Now define a test routine that we can execute to see if our dict was *)
- (* truly preserved. *)
- SendPostScript('/titleshow {dup gsave');
- SendPostScript('currentscreen 3 -1 roll pop 120 3 1 roll setscreen');
- SendPostScript('.5 setgray show grestore true charpath gsave');
- SendPostScript('1 setlinewidth 0 setgray stroke grestore');
- SendPostScript('.5 setlinewidth 1 setgray stroke }def');
- (* This ends the 'mydict begin' above, restoring md as the current dict.*)
- SendPostScript('end');
-
- (* Okay, now we have our dictionary defined, we need to kill off those *)
- (* nasty bn and bu operators before they kill us (ie. before a font *)
- (* download). *)
- (* First point to our dictionary. *)
- SendPostScript('mydict begin');
- (* Now kill off bu, saving its original definition on the stack. *)
- SendPostScript('//md /bu known {killbu} if');
- (* ...and the same for bn. *)
- SendPostScript('//md /bn known {killbn} if');
- (*************************** IMPORTANT **********************************)
- (* Since the definition of bu and bn have been saved on the stack, they *)
- (* must be restored in the opposite order that they were killed. In *)
- (* this case, bu was killed first, so restorebn must be called before *)
- (* restorebu. If not, the routines will be reversed, and you will get *)
- (* a limitcheck (out of memory) error in short order. *)
- (*************************** IMPORTANT **********************************)
- SendPostScript('end');
-
- (* Set the font using our new SetFont routine. This will set the font *)
- (* for both the Quickdraw and PostScript worlds. Since we have killed *)
- (* bn and bu, this should have no effect on our PostScript dictionary. *)
- SetFont('Times', 50, [bold]);
-
- PicComment(PostScriptBegin, 0, NIL);
- (********************************************)
- (*** Quickdraw representation of graphic. ***)
- (********************************************)
- (* These calls are only executed by Quickdraw (i.e. non-PostScript) *)
- (* devices. *)
- MoveTo(100, 100);
- DrawString('UnFancy Title');
-
- (*********************************************)
- (*** PostScript representation of graphic. ***)
- (*********************************************)
- SendPostScript('mydict begin'); (* Point to ours. *)
- SendPostScript('100 100 moveto (Fancy Title) titleshow'); (* Execute test. *)
- SendPostScript('end'); (* Reset back to last dict. *)
- PicComment(PostScriptEnd, 0, NIL);
-
- (* Now we're all done with our job, so to be polite, we restore the *)
- (* original definitions of bn and bu. REMEMBER that the restorexx *)
- (* routines must be executed in the opposite order that the killxx *)
- (* routines were. *)
- SendPostScript('mydict begin');
- SendPostScript('//md /bn known {restorebn} if');
- SendPostScript('//md /bu known {restorebu} if');
- SendPostScript('end');
- END;
-
-
- PROCEDURE PrintStuff;
- VAR
- thePrRec : THPrint;
- thePrPort : TPPrPort;
- theStatus : TPrStatus;
- oldPort : GrafPtr;
- theError : OSErr;
- theVers: INTEGER;
-
- BEGIN
- GetPort(oldPort);
- thePrRec := THPrint(NewHandle(SIZEOF(TPrint)));
-
- PrOpen;
- theVers := PrDrvrVers;
- IF PrError = noErr THEN BEGIN
- PrintDefault(thePrRec);
- IF NOT PrStlDialog(thePrRec) THEN
- ExitToShell;
- IF NOT PrJobDialog(thePrRec) THEN
- ExitToShell;
- thePrPort := PrOpenDoc(thePrRec, NIL, NIL);
- IF PrError = noErr THEN BEGIN
- PrOpenPage(thePrPort, NIL);
- IF PrError = noErr THEN BEGIN
-
- DrawStuff(thePrRec^^.prInfo.rPage);
-
- END;
- PrClosePage(thePrPort)
- END;
- PrCloseDoc(thePrPort);
- IF (thePrRec^^.prJob.bJDocLoop = bSpoolLoop) and (PrError = noErr) THEN
- PrPicFile(thePrRec, NIL, NIL, NIL, theStatus);
- END;
- PrClose;
-
- SetPort(oldPort);
- END;
-
- BEGIN
- InitGraf(@thePort); {initialize QuickDraw}
- InitFonts; {initialize Font Manager}
- FlushEvents(everyEvent, 0); {call OS Event Mgr to discard any previous events}
- InitWindows; {initialize Window Manager}
- InitMenus; {initialize Menu Manager}
- TEInit; {initialize TextEdit}
- InitDialogs(NIL); {initialize Dialog Manager}
- InitCursor; {call QuickDraw to make cursor (pointer) an arrow}
-
- PrintStuff;
- END.
-